package com.binhthuan.catechist.client;

import java.util.HashMap;
import java.util.Map;

import com.binhthuan.catechist.client.content.HomePage;
import com.binhthuan.catechist.client.content.manage.ManageArea;
import com.binhthuan.catechist.client.content.manage.ManageCourse;
import com.binhthuan.catechist.client.content.manage.ManageGrade;
import com.binhthuan.catechist.client.content.manage.ManageSchoolDate;
import com.binhthuan.catechist.client.content.manage.ManageSchoolYear;
import com.binhthuan.catechist.client.content.manage.ManageShift;
import com.binhthuan.catechist.client.content.manage.ManageStatus;
import com.binhthuan.catechist.client.content.manage.ManageVenue;
import com.binhthuan.catechist.client.content.training.AttendancePage;
import com.binhthuan.catechist.client.content.training.TraineeRegisterPage;
import com.binhthuan.catechist.client.content.training.SchedulePage;
import com.binhthuan.catechist.client.content.training.TraineeListPage;
import com.binhthuan.catechist.client.content.training.TrainerAssignmentPage;
import com.binhthuan.catechist.client.content.training.TrainerListPage;

/**
 * @author Giang Đinh - Lớp chứa các màn hình của chương trình.
 *
 */
public class ECContents {
    
    private static ECContents instance;
    private Map<String, ContentFactory> factoryMap;

    private ECContents() {
    }

    public static ECContents getInstance() {
        if(instance == null) {
            instance = new ECContents();
        }
        
        return instance;
    }

    public static Map<String, ContentFactory> getFactoryMapping() {
        return getInstance().getMapping();
    }

    public Map<String, ContentFactory> getMapping() {
        if(factoryMap == null) {
            factoryMap = new HashMap<String, ContentFactory>();
            mapFactory(HomePage.Factory.getInstance());
            mapFactory(AttendancePage.Factory.getInstance());
            mapFactory(SchedulePage.Factory.getInstance());
            mapFactory(ManageSchoolDate.Factory.getInstance());
            mapFactory(TraineeListPage.Factory.getInstance());
            mapFactory(TraineeRegisterPage.Factory.getInstance());
            mapFactory(TrainerListPage.Factory.getInstance());
            mapFactory(ManageSchoolYear.Factory.getInstance());
            mapFactory(ManageShift.Factory.getInstance());
            mapFactory(ManageArea.Factory.getInstance());
            mapFactory(ManageStatus.Factory.getInstance());
            mapFactory(ManageVenue.Factory.getInstance());
            mapFactory(ManageCourse.Factory.getInstance());
            mapFactory(ManageGrade.Factory.getInstance());
            mapFactory(TrainerAssignmentPage.Factory.getInstance());
        }
        return factoryMap;
    }

    public static ContentFactory getFactory(String factoryId) {
        return getInstance().getMapping().get(factoryId);
    }

    private void mapFactory(ContentFactory factory) {
        factoryMap.put(factory.getID(), factory);
    }
}
